$(function() {
    toastr.options = {
        "newestOnTop": false,
        "timeOut": 1500,
        "extendedTimeOut": 0,
        "escapeHtml": true,
        "positionClass": "toast-bottom-center"
    };
    if (window.currentHotel == 8) {
        $('#shop-show').removeClass('hidden');
    }
    $('#shop-show').click(function () {
        ajaxRequest('/Home/Hotel/rpcTest', {
            'hotel': window.currentHotel
        }, 'post', function(data) {
            var shopInfo = data.data;
            var shopTypeHTML = '';
            var templateShopTypeHTML = $($('#templateShopType').clone().html());
            $.each(shopInfo, function(key, shop) {
                templateShopTypeHTML.find('.img-circle').attr('src',shop.managerhead);
                templateShopTypeHTML.find('.shop-panel-type-book').attr('data-value',shop.shopinfo_id);
                templateShopTypeHTML.find('.shop-panel-type-name').text(shop.shopname);
                templateShopTypeHTML.find('.collect-num').text(shop.collect);
                templateShopTypeHTML.find('.sales-num').text(shop.sales);
                templateShopTypeHTML.find('.goods-num').text(shop.num);
                var goodsHTML = '';
                var templateGoodsHTML = $(templateShopTypeHTML.find('.shop-panel-img').clone().html());
                $.each(shop.goods, function(index, goods) {
                    templateGoodsHTML.css({
                        'background-image':'url(' + goods.cover +')',
                        'background-size':'auto 100%',
                        'background-position': 'center center'
                    });
                    templateGoodsHTML.attr('data-shop',shop.shopinfo_id);
                    templateGoodsHTML.attr('data-goods',goods.id);
                    templateGoodsHTML.find('.shop-price').text(window.symbols+goods.price);
                    goodsHTML += templateGoodsHTML.prop('outerHTML');
                })
                templateShopTypeHTML.find('.shop-panel-img').html(goodsHTML);
                shopTypeHTML += templateShopTypeHTML.prop('outerHTML');
            });
            $('#shop-panel .shop-panel-types').html(shopTypeHTML);
        }, function(error) {
            toastr.error(typeof error.responseJSON === 'undefined' ? lang('tip.system') : error.responseJSON.info);
        });
    })

    $('#shop-panel').on('click', '.shop-panel-type-book', function(e) {
        e.preventDefault();
        e.stopPropagation();
        var shopId = $(this).data('value');
        window.location.href = 'http://booking.uclbrt.com/shop/index.html?shop='+shopId;
    });

    $('#shop-panel').on('click', '.shop-panel-cover', function(e) {
        e.preventDefault();
        e.stopPropagation();
        var shopId = $(this).data('shop');
        var goodsId = $(this).data('goods');
        window.location.href = 'http://booking.uclbrt.com/shop/details/details.html?shop=' + shopId + '&id=' + goodsId + '&index=1';
    });
});
